package org.ar.xmling.dom.processors;

import java.util.List;

import org.ar.xmling.dom.XMLTagAttribute;

public class XMLTagAndAttributeProcessor extends XMLTagProcessor {
  protected List<XMLTagAttribute> attributes;

  public XMLTagAttribute findAttributeByName(String name) {
    for (XMLTagAttribute attr : attributes) {
      if (attr.getName().equals(name)) {
        return attr;
      }
    }
    return null;
  }

  public XMLTagAttribute findAttributeByValue(String value) {
    for (XMLTagAttribute attr : attributes) {
      if (attr.getValue().equals(value)) {
        return attr;
      }
    }
    return null;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (!super.equals(obj)) return false;
    if (getClass() != obj.getClass()) return false;
    XMLTagAndAttributeProcessor other = (XMLTagAndAttributeProcessor) obj;
    if (attributes == null) {
      if (other.attributes != null) return false;
    } else if (!attributes.equals(other.attributes)) return false;
    return true;
  }


}
